﻿#include"Bloom_filter.h"

//int main()
//{
//	Blomm_fiter<100> bf;
//	bf.set("吴彦祖");
//	bf.set("彭于晏");
//	bf.set("黎明");
//
//	cout << bf.test("吴彦祖") << endl;
//	cout << bf.test("彭于晏") << endl;
//	cout << bf.test("黎明") << endl;
//	cout << bf.test("古天乐") << endl;
//
//
//	return 0;
//}

void TestBloomFilter2()
{

	srand(time(0));
	const size_t N = 100000;
	//Blomm_fiter<N> bf;
	//Blomm_fiter<N, 3> bf;
	Blomm_fiter<N, 10> bf;
	//改变x，影响误判率

	std::vector<std::string> v1;
	std::string url = "https://www.cnblogs.com/-clq / archive / 2012 / 05 / 31 / 2528153.html";
		
	for (size_t i = 0; i < N; ++i)
	{
		v1.push_back(url + std::to_string(i));
	}

	for (auto& str : v1)
	{
		bf.set(str);
	}

	// v2跟v1是相似字符串集（前缀⼀样），但是后缀不⼀样
	v1.clear();
	for (size_t i = 0; i < N; ++i)
	{
		std::string urlstr = url;
		urlstr += std::to_string(99999 + i);
		v1.push_back(urlstr);
	}


	size_t n2 = 0;
	for (auto& str : v1)
	{
		if (bf.test(str)) // 误判
		{
			++n2;
		}
	}


	cout << "相似字符串误判率:" << (double)n2 / (double)N << endl;
	// 不相似字符串集 前缀后缀都不⼀样
	v1.clear();

	for (size_t i = 0; i < N; ++i)
	{
		//string url = "zhihu.com";
		string url = "孙悟空";
		url += std::to_string(i + rand());
		v1.push_back(url);
	}
	size_t n3 = 0;
	for (auto& str : v1)
	{
		if (bf.test(str))
		{
			++n3;
		}
	}
	cout << "不相似字符串误判率:" << (double)n3 / (double)N << endl;
	cout << "公式计算出的误判率:" << bf.getFalseProbability() << endl;
}
int main()
{
	TestBloomFilter2();
	return 0;
}